/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package centralizedme;

import java.util.ArrayList;

/**
 *
 * @author palexander
 */
public abstract class RdfClass {
    // property objects associated with this class
    private ArrayList<RdfProperty> properties;

    // name of the class
    private String className;
    // id of the class (used in rdf:ID)
    private String id;
    // uri to use in rdf:about
    private String about;

    // open and close tags in RDF
    private String openClass;
    private String closeClass;

    /**
     * Constructor that takes a class name.
     * @param className Name of this class.
     */
    public RdfClass(String className) {
        this.className = className;

        openClass = "<" + className + " rdf:about=\"\">\n";
        closeClass = "</" + className + ">\n";

        properties = new ArrayList<RdfProperty>();
    }

    /**
     * Constructor that uses just id or just about in the rdf tag.
     * @param className <code>String</code> of the name of this class.
     * @param useWhich  <code>int</code> designating which param to use.
     * @param s         <code>String</code> with the contents for id or about.
     */
    public RdfClass(String className, int useWhich, String s) {
        this(className);
        if (useWhich == 0) {
            this.id = s;
            openClass = "<" + className + " rdf:ID=\"" + id + "\">\n";
        } else if (useWhich == 1) {
            this.about = s;
            openClass = "<" + className + " rdf:about=\"" + about + "\">\n";
        } else {
            return;
        }
    }

    /**
     * Constructor that uses both id and about in the rdf tag.
     * @param className <code>String</code> of the name of this class.
     * @param id        <code>String</code> to use as the contents of id.
     * @param about     <code>String</code> to use as the contents of about.
     */
    public RdfClass(String className, String id, String about) {
        this(className);
        this.id = id;
        this.about = about;

        openClass = "<" + className + " rdf:id=\"" + id + "\"" +
                " rdf:about=\"" + about + "\">\n";
    }

    /**
     * String representation of this class.
     */
    @Override
    public String toString() {
        // String to build and return
        StringBuffer s = new StringBuffer();
        // open the RDF statement
        s.append(openClass);
        // loop through associated properties
        for (int i = 0; i < properties.size(); i++) {
            s.append("    " + properties.get(i).toString() + "\n");
        }
        // close the RDF statement
        s.append(closeClass);
        
        return s.toString();
    }

    /**
     * Add a property to this class.
     * @param prop  Property to be added.
     */
    public void add(RdfProperty prop) {
        properties.add(prop);
    }

    /**
     * Get the open RDF tag.
     * @return  <code>String</code> of the open RDF tag for this class.
     */
    public String getOpen() {
        return openClass;
    }

    /**
     * Get the close RDF tag.
     * @return  <code>String</code> of the close RDF tag for this class.
     */
    public String getClose() {
        return closeClass;
    }

    /**
     * Set the id of this class for use in rdf:ID.
     * @param id    <code>String</code> representing id of this class.
     */
    public void setId(String id) {
        this.id = id;
    }
}
